/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package business;

import dal.CarDetailDAL;
import java.util.ArrayList;
import java.util.List;
import model.CarDetails;

/**
 *
 * @author Nhang Con
 */
public class CarDetailBusiness {

    private CarDetailDAL cdal = new CarDetailDAL();

    public List<CarDetails> getListAllCar() {
        return cdal.getListAllCar();

    }

    public boolean updateCarDetail(CarDetails car) {
        return cdal.updateCarDetail(car);

    }

    public boolean createCarDetail(CarDetails car) {
        return cdal.createNewCar(car);

    }

    public List<CarDetails> listCarDetailByPage(int page) {
        return cdal.listCarDetailByPage(page);
    }

    public int getRowbyID() {
        return cdal.getRowInCar();
    }

    public List<CarDetails> getListSearch(String name) {
        return cdal.getSearchCar(name);

    }

    public int getRowInListCarByModelID(int modelID) {
        return cdal.listCarByModelID(modelID).size();
    }

    public List<CarDetails> ListCarByModelIDAndPage(int model, int pageID) {
        List<CarDetails> listCarByModelID = cdal.listCarByModelID(model);
        List<CarDetails> listCarByPage = new ArrayList<CarDetails>();
        for (int i = (pageID - 1) * 3; i < (pageID * 3); i++) {
            try {
                listCarByPage.add(listCarByModelID.get(i));
            } catch (IndexOutOfBoundsException e) {
                return listCarByPage;
            }
        }
        return listCarByPage;
    }

    public List<CarDetails> searchCarByPrice(float priceFrom, float priceTo) {
        return cdal.searchCarByPrice(priceFrom, priceTo);
    }

    public List<CarDetails> advanceSearchCar(String carName,float priceFrom, float priceTo) {
        return cdal.advanceSearchCar(carName, priceFrom, priceTo);
    }
}
